<Window x:Class="ScrumSprintMonitor.ConfigEditor.Views.SprintConfigurationEditorView.SprintConfigurationEditorWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:ScrumSprintMonitor.ConfigEditor"
		xmlns:SprintConfigurationEditorView="clr-namespace:ScrumSprintMonitor.ConfigEditor.Views.SprintConfigurationEditorView"
		xmlns:Behaviors="clr-namespace:ScrumSprintMonitor.UI.Wpf.Behaviors;assembly=ScrumSprintMonitor.UI.Wpf"
		Background="Gray"
		Title="Sprint Configuration"
		WindowStartupLocation="CenterOwner" ShowInTaskbar="False" Closed="OnWindowClosed" Width="600" Loaded="OnWindowLoaded" MouseLeftButtonDown="OnWindowMouseLeftButtonDown">

	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="pack://application:,,,/ScrumSprintMonitor.UI.Wpf;component/Styles/FormResourceDictionary.xaml" />
			</ResourceDictionary.MergedDictionaries>

			<local:XamlServiceLocator x:Key="serviceLocator" />

			<Style x:Key="BusyStateIndicatorStyle" TargetType="Grid">
				<Setter Property="Width" Value="18" />
				<Setter Property="Height" Value="18" />
				<Setter Property="Behaviors:BusyIndicatorBehavior.DimBackground" Value="False" />
				<Setter Property="Behaviors:BusyIndicatorBehavior.DimTransitionDuration" Value="0:0:0.5" />
			</Style>

			<Style x:Key="BaseDatePickerStyle" TargetType="{x:Type DatePicker}" BasedOn="{StaticResource {x:Type DatePicker}}">
				<Setter Property="Margin" Value="3" />
				<Setter Property="HorizontalAlignment" Value="Left" />
				<Setter Property="IsTodayHighlighted" Value="True" />
			</Style>

			<Style x:Key="BaseTimePickerStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBoxStyle}">
				<Setter Property="Margin" Value="3" />
				<Setter Property="HorizontalAlignment" Value="Stretch" />
				<Setter Property="HorizontalContentAlignment" Value="Left" />
			</Style>

			<Style x:Key="AdvanceSprintButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
				<Setter Property="Margin" Value="0,3" />
				<Setter Property="Padding" Value="6" />
			</Style>

			<!-- 
The template which renders a TextBox 
when it contains invalid data. 
-->
			<ControlTemplate x:Key="TextBoxErrorTemplate">
				<DockPanel>
					<Ellipse DockPanel.Dock="Right" Margin="2,0" ToolTip="Contains invalid data" Width="10" Height="10">
						<Ellipse.Fill>
							<LinearGradientBrush>
								<GradientStop Color="#11FF1111" Offset="0" />
								<GradientStop Color="#FFFF0000" Offset="1" />
							</LinearGradientBrush>
						</Ellipse.Fill>
					</Ellipse>
					<!-- 
	This placeholder occupies where the TextBox will appear. 
	-->
					<AdornedElementPlaceholder />
				</DockPanel>
			</ControlTemplate>

			<!-- 
The Style applied to both TextBox controls in the UI.
-->
			<Style TargetType="TextBox">
				<Setter Property="Margin" Value="4,4,10,4" />
				<Setter Property="Validation.ErrorTemplate" Value="{StaticResource TextBoxErrorTemplate}" />
				<Style.Triggers>
					<Trigger Property="Validation.HasError" Value="True">
						<Setter Property="ToolTip">
							<Setter.Value>
								<Binding Path="(Validation.Errors)[0].ErrorContent" RelativeSource="{x:Static RelativeSource.Self}" />
							</Setter.Value>
						</Setter>
					</Trigger>
				</Style.Triggers>
			</Style>
		</ResourceDictionary>
	</Window.Resources>

	<Window.Style>
		<StaticResource ResourceKey="DefaultChrome" />
	</Window.Style>

	<DockPanel Grid.IsSharedSizeScope="True" DataContext="{Binding Path=SprintConfigurationEditorViewModel, Source={StaticResource serviceLocator}}">
		<Grid DockPanel.Dock="Top">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" SharedSizeGroup="PropertyName" />
				<ColumnDefinition />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>

			<ContentControl Grid.Row="0" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" Content="Project" IsTabStop="False" Focusable="False" />

			<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="3">
				<Grid Style="{StaticResource BusyStateIndicatorStyle}" Behaviors:BusyIndicatorBehavior.BusyState="{Binding FetchingAvailableTfsProjects}" />
				<Label Margin="3,0,0,0" Style="{StaticResource LabelStyle}" Content="_Project Name:" Target="{Binding ElementName=tfsProjectNameComboBox}" />
			</StackPanel>
			<ComboBox Grid.Column="1" Grid.Row="1" Style="{StaticResource BaseComboBoxStyle}" ItemsSource="{Binding Path=AvailableTfsProjects}" SelectedItem="{Binding Path=TfsProjectName}" x:Name="tfsProjectNameComboBox" />

			<Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="2" Margin="3" Content="Process _Template:" Target="{Binding ElementName=processTemplateComboBox}" />
			<ComboBox x:Name="processTemplateComboBox" Grid.Column="1" Grid.Row="2" Style="{StaticResource BaseComboBoxStyle}" ItemsSource="{Binding Path=AvailableTfsProcessTemplates}" SelectedItem="{Binding Path=TfsProcessTemplateName}" />

			<ContentControl Grid.Row="3" Grid.ColumnSpan="2" ContentTemplate="{StaticResource Separator}" Content="Current Sprint" IsTabStop="False" Focusable="False" />

			<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="3">
				<Grid Style="{StaticResource BusyStateIndicatorStyle}" Behaviors:BusyIndicatorBehavior.BusyState="{Binding FetchingIterationPaths}" />
				<Label Margin="3,0,0,0" Style="{StaticResource LabelStyle}" Content="_Iteration Path:" Target="{Binding ElementName=iterationPathComboBox}" />
			</StackPanel>
			<ComboBox x:Name="iterationPathComboBox" Grid.Column="1" Grid.Row="4" Style="{StaticResource BaseComboBoxStyle}" ItemsSource="{Binding Path=IterationPaths}" SelectedItem="{Binding Path=CurrentIterationPath}" />

			<StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2">
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto" SharedSizeGroup="PropertyName" />
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="Auto" />
					</Grid.ColumnDefinitions>

					<Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="0" Margin="3" Content="Sprint _Start Date:" Target="{Binding ElementName=sprintStartDatePicker}" />
					<Button Command="{Binding AdvanceSprintCommand}" CommandParameter="-1" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Style="{StaticResource AdvanceSprintButtonStyle}" Content="&lt;" />
					<Grid Grid.Column="2" Grid.Row="0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="70" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<DatePicker x:Name="sprintStartDatePicker" Style="{StaticResource BaseDatePickerStyle}" SelectedDate="{Binding Path=SprintStartDate, Mode=TwoWay}" />
						<TextBox Grid.Column="1" Style="{StaticResource BaseTimePickerStyle}" Text="{Binding Path=SprintStartTimeOfDay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}" />
						<ComboBox Grid.Column="2" Style="{StaticResource BaseComboBoxStyle}" ItemsSource="{Binding Path=TimeZones}" SelectedItem="{Binding Path=SprintStartTimeZone}" />
					</Grid>

					<Label Style="{StaticResource LabelStyle}" Grid.Column="0" Grid.Row="1" Margin="3" Content="Sprint _End Date:" Target="{Binding ElementName=sprintEndDatePicker}" />
					<Grid Grid.Column="2" Grid.Row="1">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="70" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<DatePicker x:Name="sprintEndDatePicker" Style="{StaticResource BaseDatePickerStyle}" SelectedDate="{Binding Path=SprintEndDate, Mode=TwoWay}" />
						<TextBox Grid.Column="1" Style="{StaticResource BaseTimePickerStyle}" Text="{Binding Path=SprintEndTimeOfDay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}" />
						<ComboBox Grid.Column="2" Style="{StaticResource BaseComboBoxStyle}" ItemsSource="{Binding Path=TimeZones}" SelectedItem="{Binding Path=SprintEndTimeZone}" />
					</Grid>
					<Button Command="{Binding AdvanceSprintCommand}" CommandParameter="1" Grid.Column="3" Grid.Row="0" Grid.RowSpan="2" Style="{StaticResource AdvanceSprintButtonStyle}" Content="&gt;" />
				</Grid>
				<CheckBox x:Name="excludeWeekendsCheckBox" IsChecked="{Binding Path=ExcludeWeekends}" Margin="6">
					<Label Style="{StaticResource LabelStyle}" Content="Exclude weekends" Margin="0" Padding="0" Foreground="White" ToolTip="Check this box if no development is normally done on Saturdays and Sundays" Target="{Binding ElementName=excludeWeekendsCheckBox}" />
				</CheckBox>
			</StackPanel>

			<ContentControl Grid.Row="7" Grid.ColumnSpan="4" ContentTemplate="{StaticResource Separator}" Content="Continuous Integration" IsTabStop="False" Focusable="False" />

			<StackPanel Grid.Column="0" Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="3">
				<Grid Style="{StaticResource BusyStateIndicatorStyle}" Behaviors:BusyIndicatorBehavior.BusyState="{Binding FetchingBuildDefinitions}" />
				<Label Margin="3,0,0,0" Style="{StaticResource LabelStyle}" Content="_Build Definition:" Target="{Binding ElementName=buildDefinitionListBox}" />
			</StackPanel>
			<ListBox x:Name="buildDefinitionListBox" Grid.Column="1" Grid.Row="8" Style="{StaticResource BaseListBoxStyle}" MinHeight="24" ItemsSource="{Binding Path=BuildDefinitionStates}" MaxHeight="200" Focusable="False">
				<ListBox.ItemTemplate>
					<DataTemplate DataType="{x:Type SprintConfigurationEditorView:BuildDefinitionItemViewModel}">
						<CheckBox IsChecked="{Binding IsEnabled}">
							<TextBlock Padding="3" Foreground="White" Text="{Binding Name}" />
						</CheckBox>
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
		</Grid>

		<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,12,0,0">
			<Button Command="{Binding OkCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Margin="6,0,0,0" Padding="16,4" MinWidth="72" IsDefault="True" Content="O_K" />
			<Button Command="{Binding CancelCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" x:Name="cancelButton" Margin="6,0,0,0" Padding="16,4" MinWidth="72" IsCancel="True" Content="Cancel" />
			<Button Command="{Binding HelpCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" x:Name="helpButton" Margin="6,0,0,0" Padding="16,4" MinWidth="72" Content="_Help" />
		</StackPanel>
	</DockPanel>
</Window>